#include <iostream>

class Cpu{
public:
    virtual void calculate() = 0; 
};
class VideoCard{
public:
    virtual void display() = 0;
};
class Memory{
public:
    virtual void storage() = 0;
};

class IntelCpu : public Cpu{
public:
    void calculate(){
        std::cout<< "IntelCpu calculate..."<<std::endl;
    }
};
class IntelVideoCard : public VideoCard{
public:
    void display(){
        std::cout<< "IntelVideoCard display..."<<std::endl;
    }
};
class IntelMemory : public Memory{
public:
    void storage(){
        std::cout<< "IntelMemory storage..."<<std::endl;
    }
};

class computer {
public:
    Cpu *cpu;
    VideoCard *videocard;
    Memory *memory;

    computer(Cpu *cpu, VideoCard *videocard, Memory *memory){
        this->cpu = cpu;
        this->videocard = videocard;
        this->memory = memory;
    }

    ~computer(){
        if(cpu != NULL){
            delete cpu;
            cpu = NULL;
            std::cout<< "cpu 析构"<<std::endl;

        }
        if(videocard != NULL){
            delete videocard;
            videocard = NULL;
            std::cout<< "videocard 析构"<<std::endl;

        }
        if(memory != NULL){
            delete memory;
            memory = NULL;
            std::cout<< "memory 析构"<<std::endl;

        }
    }

    void start(){
        this->cpu->calculate();
        this->videocard->display();
        this->memory->storage();
    }
};

void test(){
    // Cpu *cpu = new IntelCpu;
    // VideoCard *videoCard = new IntelVideoCard;
    // Memory *memory = new IntelMemory;

    computer *c = new computer(new IntelCpu, new IntelVideoCard, new IntelMemory);
    c->start();
    delete c;
}

int main()
{
    test();
    return 0;
}